package com.bilibili.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.bilibili.dao.CommentDao;
import com.bilibili.dao.VideoAndCommentDao;
import com.bilibili.dao.impl.CommentDaoImpl;
import com.bilibili.dao.impl.VideoAndCommentDaoImpl;
import com.bilibili.dto.VideoAndComment;
import com.bilibili.entity.Page;
import com.bilibili.service.VideoAndCommentService;

public class VideoAndCommentServiceImpl implements VideoAndCommentService {

	VideoAndCommentDao vd = new VideoAndCommentDaoImpl();
	CommentDao commentDao = new CommentDaoImpl();
	@Override
	public Page<VideoAndComment> selectVideoPlayNum(int userId,int pageNum,int pageSize,String title) {
		// TODO Auto-generated method stub
		List<VideoAndComment> list = vd.selectAllVideo(userId,pageNum,pageSize,title);
		List<VideoAndComment> totalList = new ArrayList<VideoAndComment>();
		for (VideoAndComment v : list) {
			v.setCommentNum(commentDao.selectVideoPlayNum(v.getVideoId()));
			totalList.add(v);
		}
		int totalRows = vd.selectAllVideoNum(userId,title);
		Page<VideoAndComment> VideoPage = new Page<VideoAndComment>(totalList,pageNum,pageSize,totalRows);
		return VideoPage;
	}

}
